import java.io.Serializable;
import java.util.ArrayList;


public class Department implements Comparable<Department>, Serializable{
	
	private String name;
	private String location;
	private ArrayList<Employee> employees;
	private Employee head;
	
	public Department(String name, String location){
		this.name = name;
		this.location = location;
		this.employees = new ArrayList<Employee>();
		this.head = null;
	}
	
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getLocation() {
		return location;
	}

	public void setLocation(String location) {
		this.location = location;
	}
	
	public void setHead(Employee e) throws SystemException{
		if(employees.contains(e) && head == null){
			head = e;
		}
		else {
			throw new SystemException(SystemErrors.DEPARTMENT_HAS_HEAD);
		}
	}
	
	public Employee getHead(){
		return this.head;
	}
	
	public void removeHead(){
		this.head = null;
	}
	
	public void addEmployee(Employee e) throws SystemException{
		employees.add(e);
		e.setDepartment(this);
	}
	
	public void deleteEmployee(Employee e){
		if(employees.contains(e)){
			employees.remove(e);
		}
	}
	
	public ArrayList<Employee> getEmployees(){
		return employees;
	}

	@Override
	public String toString() {
		return name+" ("+location+")";
	}

	@Override
	public int compareTo(Department d) {
		return this.getName().compareTo(d.getName());
	}
	
	
}
